<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        div{
           width: 100%;
            height: 30px;
            background-color: darkblue;
        }
    </style>
</head>
<body>
<div></div>
<script>
    window.onload=()=>{
        let dom =document.querySelector('div')
        /*绑定事件组*/
        /*
        * 必须滑动过
        * 2.滑动距离超过50px
        * 3.衍生出 左滑和又滑
        * */
        let startX=0;
        let distanceX= 0;
        let isMove=false
        dom.addEventListener('touchstart',(ev)=>{
            startX =e.touches[0].clientX
        });
        dom.addEventListener('touchmove',(ev)=>{
           let moveX =e.touches[0].clientX
            distanceX =moveX - startX;
            isMove=true
        });
        dom.addEventListener('touchend',(ev)=>{
              if(isMove && Math.abs(distanceX)>=50){
                  if(distanceX>0){
                      console.log('右滑事件')
                  }else{
                      console.log("左滑事件")
                  }
              }
             startX=0;
             distanceX= 0;
             isMove=false
        })
    }
</script>
</body>
</html>